﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPIWareMVVM.ViewModels;
using DataAccess;

namespace SPIWareMVVM.Views.Commands
{
    public class AddNewPartCommand : BaseCommand
    {
        public AddNewPartCommand(BaseViewModel sender) : base(sender)
        {
            _sender = (ApplicationViewModel)sender;
        }

        public override void Execute(object parameter)
        {
            MaterialList list = (MaterialList)parameter;
            if (list != null)
            {
                list.lbMaterials.ItemsSource = null;

                Part newPart = ApplicationData.NewPart();
                ((ApplicationViewModel)_sender).SelectedMaterial = newPart;

                list.lbMaterials.ItemsSource = ApplicationData.ocParts;
                list.lbMaterials.SelectedItem = newPart;
                list.spPartInformation.DataContext = newPart;

                if (list.Visibility == System.Windows.Visibility.Collapsed) list.Visibility = System.Windows.Visibility.Visible;
            }
        }
    }
}
